*--------------------------------------------------------------------
* Military Influence and Ethnic Exclusion: A Cross-National Analysis
* Author: Bulbul Ahmed 
* Purpose: Examines military influence on ethnic discrimination (1950-2006)
*--------------------------------------------------------------------

clear all
set more off
capture log close
set scheme s2color

*--------------------------------------------------
* I. DATA SETUP AND SAMPLE DEFINITION
*--------------------------------------------------

use "cp_compfinal.dta", clear
keep if year >= 1950 & year <= 2006

global controls polity polity_squared cultural_dif mean_SEPX mean_PROT mean_REB ln_gdpcap lfirstpi time time_squared time_cubed

*--------------------------------------------------
* II. POLITICAL EXCLUSION ANALYSIS (AMAR DATA)
*--------------------------------------------------

*** Table 2: Political Exclusion Models ***

* Model 1: Military Influence → Political Exclusion
quietly logit max_POLDIS_binary mi_in $controls, robust
estimates store pol_m1

* Model 2: Military Cabinet → Political Exclusion (Mean)
quietly logit mean_POLDIS_binary actmilcabshare $controls, robust
estimates store pol_m2

* Model 3: Military Supporter → Political Exclusion
quietly logit max_POLDIS_binary mi_supporter $controls, robust
estimates store pol_m3

* Export results
esttab pol_m1 pol_m2 pol_m3 using "Table2_Political_Exclusion.rtf", replace ///
    title("Table 2: Modeling Ethnic Political Exclusion with Logistic Regression") ///
    b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) compress ///
    label wide varwidth(25) modelwidth(10) ///
    varlabels(mi_in "Military Influence Score" ///
              actmilcabshare "Military in Cabinet" ///
              mi_supporter "Military Supporter Score" ///
              _cons "Constant") ///
    order(mi_in actmilcabshare mi_supporter) ///
    nonumbers nomtitles nogaps ///
    cells(b(fmt(3) star) se(fmt(3) par)) ///
    addnotes("Robust standard errors in parentheses. * p<0.10, ** p<0.05, *** p<0.01")

*--------------------------------------------------
* III. ECONOMIC EXCLUSION ANALYSIS (AMAR DATA)
*--------------------------------------------------

*** Table 3: Economic Exclusion Models ***

* Model 1: Military Influence → Economic Exclusion
quietly logit max_ECDIS_binary mi_in $controls, robust
estimates store eco_m1

* Model 2: Military Cabinet → Economic Exclusion
quietly logit max_ECDIS_binary actmilcabshare $controls, robust
estimates store eco_m2

* Model 3: Military Supporter → Economic Exclusion
quietly logit max_ECDIS_binary mi_supporter $controls, robust
estimates store eco_m3

* Export results
esttab eco_m1 eco_m2 eco_m3 using "Table3_Economic_Exclusion.rtf", replace ///
    title("Table 3: Modeling Ethnic Economic Discrimination with Logistic Regression") ///
    b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) compress ///
    label wide varwidth(25) modelwidth(10) ///
    varlabels(mi_in "Military Influence Score" ///
              actmilcabshare "Military in Cabinet" ///
              mi_supporter "Military Supporter Score" ///
              _cons "Constant") ///
    order(mi_in actmilcabshare mi_supporter) ///
    nonumbers nomtitles nogaps ///
    cells(b(fmt(3) star) se(fmt(3) par)) ///
    addnotes("Robust standard errors in parentheses. * p<0.10, ** p<0.05, *** p<0.01")

*** Table 4: Ethnic Exclusion Models (EPR) ***

* Model 1: Military Influence → Ethnic Exclusion
quietly reg exclpop mi_in $controls, robust
estimates store epr_m1

* Model 2: Military Supporter → Ethnic Exclusion
quietly reg exclpop mi_supporter $controls, robust
estimates store epr_m2

* Model 3: Military Cabinet → Ethnic Exclusion
quietly reg exclpop actmilcabshare_cat $controls, robust
estimates store epr_m3

* Export results
esttab epr_m1 epr_m2 epr_m3 using "Table4_EPR_Exclusion.rtf", replace ///
    title("Table 4: Modeling Ethnic Exclusion with EPR Dataset") ///
    b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) compress ///
    label wide varwidth(25) modelwidth(10) ///
    varlabels(mi_in "Military Influence Score" ///
              mi_supporter "Support for Military" ///
              actmilcabshare_cat "Military in Cabinet" ///
              _cons "Constant") ///
    order(mi_in mi_supporter actmilcabshare_cat) ///
    nonumbers nomtitles nogaps ///
    cells(b(fmt(3) star) se(fmt(3) par)) ///
    addnotes("Robust standard errors in parentheses. * p<0.10, ** p<0.05, *** p<0.01")

*--------------------------------------------------
* V. MARGINAL EFFECTS AND VISUALIZATION
*--------------------------------------------------

*** Figure 1: Political Exclusion Margins ***

* Panel A: Military Influence
quietly logit max_POLDIS_binary mi_in $controls, robust
margins, at(mi_in=(0(1)3))
marginsplot, ///
    title("Political Discrimination/Exclusion", size(medium)) ///
    ylabel(, angle(horizontal) nogrid) ///
    xlabel(, angle(horizontal) nogrid) ///
    xtitle("Military Influence Score (Model 1)", size(small)) ///
    ytitle("Pr(Political Discrimination/Exclusion)", size(small)) ///
    plotopts(lwidth(medium) lcolor(blue) msymbol(circle) mcolor(blue) msize(small)) ///
    ciopts(lcolor(blue%50) lpattern(shortdash)) ///
    legend(off) name(plot1, replace) ///
    graphregion(color(white)) plotregion(color(gs16)) ///
    scheme(s2color)

* Panel B: Military Cabinet
quietly logit mean_POLDIS_binary actmilcabshare $controls, robust
margins, at(actmilcabshare=(0(.5)1))
marginsplot, ///
    title("Political Discrimination/Exclusion", size(medium)) ///
    ylabel(, angle(horizontal) nogrid) ///
    xlabel(, angle(horizontal) nogrid) ///
    xtitle("Military in Cabinet (Model 2)", size(small)) ///
    ytitle("", size(small)) ///
    plotopts(lwidth(medium) lcolor(red) msymbol(square) mcolor(red) msize(small)) ///
    ciopts(lcolor(red%50) lpattern(shortdash)) ///
    legend(off) name(plot2, replace) ///
    graphregion(color(white)) plotregion(color(gs16)) ///
    scheme(s2color)

* Panel C: Military Supporter
quietly logit max_POLDIS_binary mi_supporter $controls, robust
margins, at(mi_supporter=(0(.5)1))
marginsplot, ///
    title("Political Discrimination/Exclusion", size(medium)) ///
    ylabel(, angle(horizontal) nogrid) ///
    xlabel(, angle(horizontal) nogrid) ///
    xtitle("Military Supporter Score (Model 3)", size(small)) ///
    ytitle("", size(small)) ///
    plotopts(lwidth(medium) lcolor(green) msymbol(triangle) mcolor(green) msize(small)) ///
    ciopts(lcolor(green%50) lpattern(shortdash)) ///
    legend(off) name(plot3, replace) ///
    graphregion(color(white)) plotregion(color(gs16)) ///
    scheme(s2color)

* Combine panels
graph combine plot1 plot2 plot3, ///
    title("Figure 1: Combined Margis Plots of Ethnic Political Exclusion (AMAR)", ///
          size(medium) color(black)) ///
    subtitle("Combined Margins Plots for Ethnic Political Discrimination/Exclusion" ///
             "{break}95% Confidence Intervals", ///
             size(small) color(black)) ///
    ycommon cols(3) ///
    graphregion(color(white)) ///
    scheme(s2color)

graph export "Figure1_Political_Margins.png", replace width(1200) height(400)

*** Figure 2: Economic Exclusion Margins ***

* Panel A: Military Influence
quietly logit max_ECDIS_binary mi_in $controls, robust
margins, at(mi_in=(0(1)3))
marginsplot, ///
    title("Economic Discrimination/Exclusion", size(medium)) ///
    ylabel(, angle(horizontal) nogrid) ///
    xlabel(, angle(horizontal) nogrid) ///
    xtitle("Military Influence Score (Model 1)", size(small)) ///
    ytitle("Pr(Economic Discrimination/Exclusion)", size(small)) ///
    plotopts(lwidth(medium) lcolor(blue) msymbol(circle) mcolor(blue) msize(small)) ///
    ciopts(lcolor(blue%50) lpattern(shortdash)) ///
    legend(off) name(plot1, replace) ///
    graphregion(color(white)) plotregion(color(gs16)) ///
    scheme(s2color)

* Panel B: Military Cabinet  
quietly logit max_ECDIS_binary actmilcabshare $controls, robust
margins, at(actmilcabshare=(0(.5)1))
marginsplot, ///
    title("Economic Discrimination/Exclusion", size(medium)) ///
    ylabel(, angle(horizontal) nogrid) ///
    xlabel(, angle(horizontal) nogrid) ///
    xtitle("Military in Cabinet (Model 2)", size(small)) ///
    ytitle("", size(small)) ///
    plotopts(lwidth(medium) lcolor(red) msymbol(square) mcolor(red) msize(small)) ///
    ciopts(lcolor(red%50) lpattern(shortdash)) ///
    legend(off) name(plot2, replace) ///
    graphregion(color(white)) plotregion(color(gs16)) ///
    scheme(s2color)

* Panel C: Military Supporter
quietly logit max_ECDIS_binary mi_supporter $controls, robust
margins, at(mi_supporter=(0(.5)1))
marginsplot, ///
    title("Economic Discrimination/Exclusion", size(medium)) ///
    ylabel(, angle(horizontal) nogrid) ///
    xlabel(, angle(horizontal) nogrid) ///
    xtitle("Military Supporter Score (Model 3)", size(small)) ///
    ytitle("", size(small)) ///
    plotopts(lwidth(medium) lcolor(green) msymbol(triangle) mcolor(green) msize(small)) ///
    ciopts(lcolor(green%50) lpattern(shortdash)) ///
    legend(off) name(plot3, replace) ///
    graphregion(color(white)) plotregion(color(gs16)) ///
    scheme(s2color)

* Combine panels
graph combine plot1 plot2 plot3, ///
    title("Figure 2: Combined Margis Plots of Ethnic Economic Exclusion (AMAR)", ///
          size(medium) color(black)) ///
    subtitle("Combined Margins Plots for Ethnic Economic Discrimination/Exclusion" ///
             "{break}95% Confidence Intervals", ///
             size(small) color(black)) ///
    ycommon cols(3) ///
    graphregion(color(white)) ///
    scheme(s2color)

graph export "Figure2_Economic_Margins.png", replace width(1200) height(400)

*** Figure 3: EPR Exclusion Margins ***

* Panel A: Military Influence
quietly reg exclpop mi_in $controls, robust
margins, at(mi_in=(0(1)3))
marginsplot, ///
    title("Ethnic Exclusion", size(medium)) ///
    ylabel(, angle(horizontal) nogrid) ///
    xlabel(, angle(horizontal) nogrid) ///
    xtitle("Military Influence Score", size(small)) ///
    ytitle("Linear prediction", size(small)) ///
    plotopts(lwidth(medium) lcolor(blue) msymbol(circle) mcolor(blue) msize(small)) ///
    ciopts(lcolor(blue%50) lpattern(shortdash)) ///
    legend(off) name(plot1, replace) ///
    graphregion(color(white)) plotregion(color(gs16)) ///
    scheme(s2color)

* Panel B: Military Supporter
quietly reg exclpop mi_supporter $controls, robust
margins, at(mi_supporter=(0(.5)1))
marginsplot, ///
    title("Ethnic Exclusion", size(medium)) ///
    ylabel(, angle(horizontal) nogrid) ///
    xlabel(, angle(horizontal) nogrid) ///
    xtitle("Military Supporter Score", size(small)) ///
    ytitle("Linear prediction", size(small)) ///
    plotopts(lwidth(medium) lcolor(red) msymbol(square) mcolor(red) msize(small)) ///
    ciopts(lcolor(red%50) lpattern(shortdash)) ///
    legend(off) name(plot2, replace) ///
    graphregion(color(white)) plotregion(color(gs16)) ///
    scheme(s2color)

* Panel C: Military Cabinet
quietly reg exclpop actmilcabshare_cat $controls, robust
margins, at(actmilcabshare_cat=(0(.5)1))
marginsplot, ///
    title("Ethnic Exclusion", size(medium)) ///
    ylabel(, angle(horizontal) nogrid) ///
    xlabel(, angle(horizontal) nogrid) ///
    xtitle("Military in Cabinet", size(small)) ///
    ytitle("Linear prediction", size(small)) ///
    plotopts(lwidth(medium) lcolor(green) msymbol(triangle) mcolor(green) msize(small)) ///
    ciopts(lcolor(green%50) lpattern(shortdash)) ///
    legend(off) name(plot3, replace) ///
    graphregion(color(white)) plotregion(color(gs16)) ///
    scheme(s2color)

* Combine panels
graph combine plot1 plot2 plot3, ///
    title("Figure 3: Combined Margis Plots of Ethnic Exclusion in Percentage (EPR)", ///
          size(medium) color(black)) ///
    subtitle("Combined Margins Plots for Ethnic Exclusion in %, EPR" ///
             "{break}95% Confidence Intervals", ///
             size(small) color(black)) ///
    ycommon cols(3) ///
    graphregion(color(white)) ///
    scheme(s2color)

graph export "Figure3_EPR_Margins.png", replace width(1200) height(400)

*--------------------------------------------------
* VI. COMPLETION
*--------------------------------------------------

display _newline "Analysis completed: Tables 2-4 and Figures 1-3 generated."
display "Sample: 1950-2006 | Models: Logistic (Tables 2-3), OLS (Table 4)"

*--------------------------------------------------------------------